package com.example.springpethospital.entity;

import javax.servlet.http.HttpServletRequest;

public class Illcase {
    public Integer id;
    public String name;
    public String reception;
    public String examination;
    public String diagnostic;
    public String treatment;

    public Illcase(String name, String reception, String examination, String diagnostic, String treatment) {
        this(null, name, reception, examination, diagnostic, treatment);
    }

    public Illcase(Integer id, String name, String reception, String examination, String diagnostic, String treatment) {
        this.id = id;
        this.name = name;
        this.reception = reception;
        this.examination = examination;
        this.diagnostic = diagnostic;
        this.treatment = treatment;
    }

    public static Illcase getCaseFromRequest(HttpServletRequest request) {
        String name = request.getParameter("name");
        String reception = request.getParameter("reception");
        String examination = request.getParameter("examination");
        String diagnostic = request.getParameter("diagnostic");
        String treatment = request.getParameter("treatment");
        String sid = request.getParameter("id");
        if (sid != null && !sid.isEmpty()) {
            int id = Integer.parseInt(sid);
            return new Illcase(id, name, reception, examination, diagnostic, treatment);
        } else {
            return new Illcase(name, reception, examination, diagnostic, treatment);
        }
    }
}